<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        // es5造类
        function Person(name,age){
            this.name = name;
            this.age = age;
        }
        Person.prototype.sayName = function (){
            return this.name;
        }
        let p1 = new Person('小马哥',28);
        console.log(p1);


        // es6
        class Person2{
            constructor(name,age) {
                this.name = name;
                this.age = age;
            }
            sayName(){
                return this.name;
            }

            sayAge(){
                return this.age;
            }
        }
        // 通过Object.assign()方法一次性向类中添加多个方法
        Object.assign(Person2.prototype,{
            addNewFunc(){
                return '添加新方法';
            }
        })
        let p2 = new Person2('小马哥',28);
        console.log(p2)
    </script>
</body>
</html>